package com.gl.glbooks.repository;

import java.util.Date;
import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import com.gl.glbooks.vos.Prestamo;

@Repository
public class JpaPrestamosRepository extends JpaProjectRepository<Prestamo> implements
		PrestamosRepository<Prestamo> {

	@Override
	public List<Prestamo> getListBusquedaDate(String atributo, Date dato) {
		Query query = null;
		try {
			query = em.createQuery("SELECT obj FROM Prestamo obj WHERE obj.prestamoIndefinido = false AND obj."+atributo+" = :param");
			query.setParameter("param", dato);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return query.getResultList();
	}
	
	@Override
	public List<Prestamo> getListBusquedaDateMayor(String atributo, Date dato) {
		Query query = null;
		try {
			query = em.createQuery("SELECT obj FROM Prestamo obj WHERE obj."+atributo+" <= :param");
			query.setParameter("param", dato);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return query.getResultList();
	}
	
	
}
